using System.Windows.Forms;
using Mbs.Modularity.AddIns;
using Mbs.Elements;
using Mbs.ComponentModel.Container;

namespace Mbs.Windows.Elements.Builders
{
    [Component(Id = "ToolStrip.TextBox", Service = typeof(IElementBuilder))]
    public class ToolStripTextBoxBuilder : ToolStripItemBuilder<ToolStripTextBox>
    {
        private class TextBox : ToolStripTextBox,IAddInItemHost
        {
            public string Command;
            public IAddInItem AddInItem { get; internal set; }
            protected override void OnKeyDown(KeyEventArgs e)
            {
                base.OnKeyDown(e);
                if (e.KeyCode == Keys.Enter && !string.IsNullOrEmpty(Command))
                    Command.Publish(this, e);
            }
        }

        protected override ToolStripTextBox CreateItem(IAddInItem addInItem)
        {
            var item = new TextBox { Name = AddInItem.Path,AddInItem =addInItem,  Command = AddInItem.Command };
            return item;
        }

    }
}
